import Vue from 'vue'
import VueRouter from 'vue-router'

import XhdlView from '../views/StaticPage/XhdlView.vue'
Vue.use(VueRouter)
const routes = [
  
  {
    path: '/',
    name: 'home',
    component: XhdlView,
  },
]
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to, from, next) => {
  const publicPages = ['/', '/register', '/email', '/resetPwd', '/tel', '/configresetpwd', '/login'];
  const authRequired = !publicPages.includes(to.path);
  const loggedIn = localStorage.getItem('TOKEN');
  if (authRequired && !loggedIn) {
    return next('/login');
  }
  next(); 
});

export default router
